package com.d0323;

import java.io.*;


public class ByteArrayOutputStreamTest {
    static byte[] mybuffer;

    public static void main(String[] args) {
        Output();
        Input();
    }
    //将数据写入内存
    public static void Output() {
        ByteArrayOutputStream baos=new ByteArrayOutputStream();
        DataOutputStream dos=new DataOutputStream(baos);
        try {
            dos.writeUTF("icss");
            dos.writeInt(56);
            dos.writeDouble(3.14);
            mybuffer=baos.toByteArray();
            dos.close();
            baos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
        //将内存数据读入
    public static void Input(){
        ByteArrayInputStream bais=new ByteArrayInputStream(mybuffer);
        DataInputStream dis=new DataInputStream(bais);
        try {
            System.out.println(dis.readUTF());
            System.out.println(dis.readDouble());
            System.out.println(dis.readInt());
            dis.close();
            bais.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
